import jwt


class MyJwt():
    def __init__(self) -> None:
        self.secretkey = '12312445235ddgadhwrhgsdbv#$@#^ASF'

    # 加密
    def jwt_encode(self, data):
        return jwt.encode(data, self.secretkey, algorithm='HS256')

    # 解密
    def jwt_decode(self, token):
        return jwt.decode(token, self.secretkey, algorithms='HS256')

    # 对比
    def check(self, token):
        try:
            payload = self.jwt_decode(token)
        except:
            return False
            # data = {'data':payload}
        new_token = self.jwt_encode(payload)
        if new_token == token:
            return True
        else:
            return False


myjwt = MyJwt()